import {reqGetGoodsInfo,reqAddCart} from '@/api';
import {getUUID} from '@/utils/uuid_token';

const state={
    goodsInfo:{},
    uuid_token:getUUID()
};
const mutations={
    GETGOODSINFO(state,goodsInfo){
        state.goodsInfo=goodsInfo;
    }
};
const actions={
    async getGoodsInfo({commit},skuId){
        let result= await reqGetGoodsInfo(skuId);
        if(result.code==200){
            // console.log(result);
            commit('GETGOODSINFO',result.data);
        }
    },
    async addCart({commit},{skuId,skuNum}){
        let result=await reqAddCart(skuId,skuNum);
        if(result.code==200){
            // console.log(result);
            return 'Ok';
        }else{
            Promise.reject(new Error('失败'));
        }
    }
};
const getters={
    categoryView(state){
        return state.goodsInfo.categoryView||{};
    },
    skuInfo(state){
        return state.goodsInfo.skuInfo||{};
    },
    spuSaleAttrList(state){
        return state.goodsInfo.spuSaleAttrList||[];
    },
    
};

export default {
    state,
    mutations,
    actions,
    getters
}